package com.renbang.action.home;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.renbang.model.common.AjaxResult;
import com.renbang.model.common.Page;
import com.renbang.model.home.Article;
import com.renbang.service.home.ArticleService;
import com.renbang.action.BaseAction;
/**
 * 该代码由程序生成
 */
@Controller
@RequestMapping(value = "user/home/Article")
public class ArticleAction  extends BaseAction<Article>{
	@Autowired
	ArticleService articleService;
	
	
	//打开新增或修改页面
	@RequestMapping(value = "/editForm")
	public String editForm(Integer id, HttpServletRequest request) {
		Article article;
		if (id != null) {
			article = articleService.findById(id);
			System.out.println(article.getId()+"ArticleAction.editForm()"+article.getArticleName());
			request.setAttribute("obj", article);
		}
		return "developer/Article-form";
	}
	@RequestMapping(value = "/addOrModify")
	public  @ResponseBody AjaxResult insertOrUpdata(HttpServletRequest request,
	Article article) {
		if(article.getId()!=null){
			int i = articleService.modify(article);
			if (i > 0)
				return new AjaxResult(AjaxResult.STATUS_OK, "f成功");
			else
				return new AjaxResult(AjaxResult.STATUS_OK, "修改失败");
	} else {
		 int i = articleService.add(article);
		 if (i > 0)
		 	return new AjaxResult(AjaxResult.STATUS_OK, "增加成功");
		 else
			return new AjaxResult(AjaxResult.STATUS_OK, "增加失败");
	}
		
	}
	
}
